package com.wisdytech.linkdcs.tool.action;


import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.handler.ResourceMatchingService;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.system.model.SysUser;
import com.wisdytech.linkdcs.system.service.ISystemUserService;
import com.wisdytech.linkdcs.tool.model.TtEqTool;
import com.wisdytech.linkdcs.tool.service.IToolMaintainRecordService;
import com.wisdytech.linkdcs.tool.service.ITtEqToolService;
import com.wisdytech.linkdcs.tool.vo.ToolMaintainVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhanghailin
 * @since 2018-06-11
 */
@Controller
@RequestMapping("/tool/maintain")
public class ToolMaintainAction {

    @Resource
    private ITtEqToolService ttEqToolService;

    @Resource(name="systemUserService")
    private ISystemUserService systemUserService;

    @Resource
    private IToolMaintainRecordService toolMaintainRecordService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;

    /**
     *
     * <p>Description: 工装保养</p>
     * @param model model
     * @return String
     */
    @RequestMapping("/index")
    public String toolMaintainIndex(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "tool/toolMaintain";
    }

    @RequestMapping(value = "/getToolMaintainList/get.mvc")
    @ResponseBody
    public StandardTableResult<TtEqTool> getToolMaintainList(String toolCode, String toolName,String toolModel,String toolType,String nextMaintainDateStart,String nextMaintainDateEnd, Filter filter) {
        PageInfo<TtEqTool> page = ttEqToolService.getToolMaintainList(toolCode,toolName,toolModel,toolType,nextMaintainDateStart,nextMaintainDateEnd,filter);
        return new StandardTableResult<>(page.getTotal(),page.getList());
    }

    @RequestMapping(value = "/getToolMaintainInfo/get.mvc")
    @ResponseBody
    public StandardResult getToolMaintainInfo(String toolCode) {
        ToolMaintainVO vo = ttEqToolService.getToolMaintainInfo(toolCode);
        return StandardResult.getSuccessResult(vo);
    }

    @RequestMapping(value = "/toolMaintain/save.mvc")
    @ResponseBody
    public StandardResult toolMaintain(@RequestBody ToolMaintainVO vo) {
        SysUser operator = BaseUtil.getCurrentUser();
        this.toolMaintainRecordService.toolMaintain(vo,operator);
        return StandardResult.getSuccessResult();
    }

    @RequestMapping(value = "/getUserPageList/get.mvc")
    @ResponseBody
    public StandardResult getToolMaintainInfo(String search,Filter filter) {
        PageInfo<SysUser> page = ttEqToolService.getUserPageList(search,filter);
        return StandardResult.getSuccessResult(page.getList());
    }

    @RequestMapping(value = "/getUserInfoByUserName/get.mvc")
    @ResponseBody
    public StandardResult getUserInfoByUserName(String username) {
        SysUser user = this.systemUserService.getUserByName(username);
        return StandardResult.getSuccessResult(user);
    }


}

